#include "WOP_Obj_Entry.h"
//這個include WOPM是經由VC ++給予的"新增include目錄"功能，把前方的路徑省略
//所以如果換其他的IDE發現路徑錯誤，請自行更改路徑。
//元件原位址:"wopm/WOPM.h"
//#include "include/MappingTree.h"
//#include "WVnode.h"
//#include "VVnode.h"
#include <map>
#include <cassert>
#include "Command_Agent.h"
//#include "include/MappingDialogProxy.h"
#include "DIVA_Manager.h"

const int UNFOLD_BLOCK = 9999 ;
using namespace std;

BOOL CALLBACK CompObjProc(HWND,UINT,WPARAM,LPARAM);
extern WOP_Entry* currentEntry;
extern xMappingTree* mTree;

extern HINSTANCE _hInst ;  // this instance is defined in DIVA_MAIN
extern HWND _hWnd ;        // this instance is defined in DIVA_Application

WOP_Obj_Entry::WOP_Obj_Entry(string name, WOP_Entry *parent){
	init(name, parent);
}
string WOP_Obj_Entry::getClassName() { 
		return Command_Agent::getInstance()->getClassName(_vartype);
		// return _vartype;
		/*std::string className = _name.substr(0,_name.find(FLAG_AT));
		assert(className != "");
		return className;*/
	}
string WOP_Obj_Entry::getActualPath(string name){
	assert(false);
	assert(_updated);
	return "" ;
	//return _refpath+"."+name;
}

void WOP_Obj_Entry::unfold() {
	// Command_Agent::getInstance()->unfold
}

std::map<std::string,std::string> WOP_Obj_Entry::getVarTypeMap() {

	if (_name_type_map.size() == 0) {
		std::vector<WOP_Entry *>* child_wops = this->getChildsPtr() ;
		std::vector<WOP_Entry*>::iterator itr;
		for (itr = child_wops->begin(); itr != child_wops->end(); itr++) {
			_name_type_map[(*itr)->getName()] = (*itr)->getTypeStr();
		}
	}
	return _name_type_map ;
}
vector<pair<string, string>> WOP_Obj_Entry::getVarTypeVector() {
	vector<pair<string, string>> ret ;
	vector<WOP_Entry *>* child_wops = this->getChildsPtr() ;
	vector<WOP_Entry*>::iterator itr;
	for (itr = child_wops->begin(); itr != child_wops->end(); itr++) {
		ret.push_back(pair<string,string>((*itr)->getName(), (*itr)->getTypeStr()));
	}
	return ret ;
}




WOP_Entry * WOP_Obj_Entry::getChildEntryByName(std::string name) {

	std::vector<WOP_Entry *>* child_wops = this->getChildsPtr() ;
	std::vector<WOP_Entry*>::iterator itr;
	for (itr = child_wops->begin(); itr != child_wops->end(); itr++) {
		if ((*itr)->getName() == name) 
			return (*itr) ;
	}
	assert(false);
	return NULL ;

}